--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

-- CALL uvse_ExistsOrCreate('PAR_ACTIVITE');
delete from se_par_activite;

 INSERT INTO se_par_activite
 (SELECT ID activite_cod,
         NULL cptjov_cod,
         NULL sectcial_cod,
         NULL refe_cod,
         NULL refe_ind,
         NULL enreg_id,
         NULL percomm_cod,
         NULL naturepiece_cod,
         NULL cptjoa_cod,
         'N' enreg_s,
         activite activite_lib,
         NULL activite_lib2,
         NULL critlibre1_val,
         NULL critlibre2_val,
         NULL critlibre3_val,
         NULL critlibre4_val
    FROM uv_pactivites_four ) ;

 UPDATE se_par_activite tf SET enreg_id=(select enreg_id FROM &erp.par_activite f WHERE f.activite_cod=tf.activite_cod) ;
 UPDATE se_par_activite tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL;

 /*SELECT * FROM se_par_activite*/
 /*select * from erp_mli2.par_activite*/

 CALL uvse_synchroverserp('enreg_id','PAR_ACTIVITE','O') ;

 commit;


select * from (
SELECT &outils.stragg(source) source,activite_cod, cptjov_cod, sectcial_cod, refe_cod, refe_ind, enreg_id, percomm_cod, naturepiece_cod, cptjoa_cod, enreg_s, activite_lib, activite_lib2, critlibre1_val, critlibre2_val, critlibre3_val, critlibre4_val
FROM (
  SELECT 'uv' source ,g.* FROM se_par_activite g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_activite g
  )
GROUP BY activite_cod, cptjov_cod, sectcial_cod, refe_cod, refe_ind, enreg_id, percomm_cod, naturepiece_cod, cptjoa_cod, enreg_s, activite_lib, activite_lib2, critlibre1_val, critlibre2_val, critlibre3_val, critlibre4_val
HAVING Count(1)!=2) r
ORDER BY activite_cod;




